package com.example.campuslink.ui.activity

import com.example.campuslink.BR
import com.example.campuslink.R
import com.example.campuslink.commen.adpter.ViewPagerAdapter
import com.example.campuslink.databinding.ActivityPublicInvitationBinding
import com.example.campuslink.ui.fragment.CameraFragment
import com.example.campuslink.ui.fragment.PhotoFragment
import com.example.campuslink.ui.fragment.RecordFragment
import com.example.campuslink.ui.fragment.WordsFragment
import com.example.campuslink.viewModel.PublicInvitationViewModel

class PublicInvitationActivity :
    BaseActivity<ActivityPublicInvitationBinding, PublicInvitationViewModel>(
        PublicInvitationViewModel::class.java,
        R.layout.activity_public_invitation,
        BR.viewModel
    ) {
    private var viewPagerAdapter: ViewPagerAdapter? = null

    override fun initView() {
        init()
        onClick()
        listOf(
            WordsFragment(),
            PhotoFragment(),
            CameraFragment(),
            RecordFragment()
        ).forEach {
            viewPagerAdapter?.addFragment(it)
        }
        mViewDataBinding?.vpFragment?.adapter = viewPagerAdapter
        mViewDataBinding?.vpFragment?.isUserInputEnabled = false
    }

    fun onClick() {
        mViewDataBinding?.rgPublicTab?.setOnCheckedChangeListener({ group, checkedId ->
            when (checkedId) {
                R.id.rb_words -> {
                    mViewDataBinding?.vpFragment?.currentItem = 0
                }

                R.id.rb_photo -> {
                    mViewDataBinding?.vpFragment?.currentItem = 1
                }

                R.id.rb_camera -> {
                    mViewDataBinding?.vpFragment?.currentItem = 2
                }

                R.id.rb_record -> {
                    mViewDataBinding?.vpFragment?.currentItem = 3
                }
            }
        })
    }

    fun init() {
        mViewModel?.context = this
        mViewModel?.initDB(this)
        viewPagerAdapter = ViewPagerAdapter(this)
    }
}